import React from "react";
import axios from "axios";
import {getUrlFor} from "@/services/UrlConfig";
import {formatResult} from "@/services/Utils";

const fetchAllBus = async (params: API.PageParams,
                               sort: Record<string, 'ascend'|'descend'|null>|null,
                               filter: Record<string, React.ReactText[]|null>|null) => {

  const reqParams = {
    start: params.current,
    size: params.pageSize
  }
  console.log(params, sort, filter);
  const res = await axios.get(getUrlFor("/bus", reqParams));
  return formatResult(res)
}

const addBus = async (busInfo: Domain.Bus) => {

  await axios.post(getUrlFor("/bus"), busInfo);

}

const rmBus = async (busNum: string|undefined) => {
  await axios.delete(getUrlFor("/bus/"+busNum));
}

const updateBus = async (busNum: string|undefined, info: Domain.Bus) => {
  await axios.put(getUrlFor("/bus/"+busNum), info);
}

export {fetchAllBus, addBus, rmBus, updateBus}
